<template>
	<view class="role">
		<scroll-view scroll-y class="content">
			<view class="box">
				<view class="title">
					<image :src="`${baseImageUrl}/home/xs2.png`"></image>
					<text>选择角色</text>
					<image :src="`${baseImageUrl}/home/xs2.png`"></image>
				</view>
				<view class="swiper">
					<u-swiper-role :list="list" keyName="img" circular showOther height="240" :autoplay="false"
						previousMargin="100" nextMargin="100" @click="itemClick" @change="change"
						:current="current"></u-swiper-role>
					<!-- <u-swiper :list="list" keyName="img" circular height="243" :autoplay="false"
						previousMargin="100" nextMargin="100" @click="change" :current="current"></u-swiper> -->
				</view>
				<view class="synopsis">{{synopsis}}</view>
				<view class="btn">
					<view @click="submit">确认</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		userRole,
		userRoleSelect
	} from '@/request/api.js';
	import {
		baseImageUrl
	} from "@/utils/config.js";
	export default {
		data() {
			return {
				1: `${baseImageUrl}/role/1.png`,
				2: `${baseImageUrl}/role/2.png`,
				3: `${baseImageUrl}/role/3.png`,
				4: `${baseImageUrl}/role/4.png`,
				5: `${baseImageUrl}/role/5.png`,

				list: [],
				current: 0,
				synopsis: ""
			}
		},
		async onLoad() {
			let {
				role
			} = await userRole();
			role.forEach(item => {
				let id = item.id;
				item.img = this[id];
			});
			this.list = role;
			this.synopsis = this.list[this.current].synopsis;
		},
		methods: {
			itemClick(index) {
				this.current = index;
			},
			change(e) {
				this.current = e.current;
				this.synopsis = this.list[this.current].synopsis;
			},
			async submit() {
				let role_id = this.list[this.current].id;
				await userRoleSelect({
					role_id
				});
				this.$u.toast("选择成功");
				setTimeout(() => {
					this.redirectRouter(3);
				}, 1000);
			}
		}
	}
</script>

<style scoped lang="scss">
	.role {
		width: 100%;
		height: 1624rpx;
		padding-top: 620rpx;
		padding-bottom: 100rpx;
		box-sizing: border-box;
		background: url(#{$baseImageUrl}/login/bg.png) no-repeat;
		background-size: 100% 100%;

		.content {
			width: 100%;
			height: calc(1624rpx - 720rpx);
			box-sizing: border-box;
			background-color: rgba(0, 0, 0, 0.5);

			.box {
				height: 900rpx;
				border-top: 4rpx solid rgba(178, 178, 178, 0.3);
				border-bottom: 4rpx solid rgba(178, 178, 178, 0.3);

				.title {
					height: 100rpx;
					display: flex;
					justify-content: center;
					align-items: center;

					image {
						width: 32rpx;
						height: 32rpx;
					}

					text {
						color: #fff;
						font-size: 32rpx;
						font-weight: 400;
						font-family: SimSun;
						padding: 0 15rpx;
						box-sizing: border-box;
					}
				}

				.btn {
					display: flex;
					justify-content: center;

					view {
						width: 204rpx;
						height: 74rpx;
						line-height: 74rpx;
						text-align: center;
						color: #FFFFFF;
						font-size: 30rpx;
						font-weight: 400;
						font-family: SimSun;
						background: url(#{$baseImageUrl}/common/btn.png) no-repeat;
						background-size: 100% 100%;
					}
				}
			}
		}

		.synopsis {
			width: 100%;
			height: 230rpx;
			line-height: 36rpx;
			color: #FFFFFF;
			font-size: 24rpx;
			font-weight: 400;
			font-family: SimSun;
			padding: 20rpx;
			box-sizing: border-box;

		}

		/deep/ .u-swiper {
			background-color: transparent !important;

			.show {
				width: 100%;
				display: flex;
				justify-content: center;
				align-items: center;
				position: absolute;
				left: 0;
				bottom: 0;
				z-index: 2;

				.name {
					width: 211rpx;
					height: 65rpx;
					line-height: 65rpx;
					text-align: center;
					color: #494338;
					font-size: 48rpx;
					font-weight: 400;
					font-family: LiSu;
					background: url(#{$baseImageUrl}/home/name.png) no-repeat;
					background-size: 100% 100%;
				}
			}

			.other {}
		}
	}
</style>